<?php
// 检查MySQL用户数据
try {
    // MySQL连接配置（与服务器相同）
    $host = '113.44.136.17';
    $port = '3306';
    $database = 'qiandao';
    $username = 'qiandao';
    $password = 'NGbks3HWx5PhSxDX';
    $charset = 'utf8mb4';

    $dsn = "mysql:host={$host};port={$port};dbname={$database};charset={$charset}";
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查用户数据 ===\n";
    $stmt = $pdo->query("SELECT id, name, card_no, img FROM checkin_member WHERE status = 1 LIMIT 5");
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo "ID: {$row['id']}, 姓名: {$row['name']}, 卡号: {$row['card_no']}, 头像: {$row['img']}\n";
    }
    
    echo "\n=== 检查数据表结构 ===\n";
    $tables = ['checkin_member', 'system_checkin_log', 'checkin_device_log'];
    foreach ($tables as $table) {
        try {
            $stmt = $pdo->query("SHOW TABLES LIKE '$table'");
            if ($stmt->fetch()) {
                echo "✓ 表 $table 存在\n";
                
                // 显示表结构
                if ($table === 'checkin_member') {
                    $stmt = $pdo->query("DESCRIBE $table");
                    echo "  字段: ";
                    $fields = [];
                    while ($field = $stmt->fetch()) {
                        $fields[] = $field['Field'];
                    }
                    echo implode(', ', $fields) . "\n";
                }
            } else {
                echo "✗ 表 $table 不存在\n";
            }
        } catch (Exception $e) {
            echo "✗ 检查表 $table 时出错: " . $e->getMessage() . "\n";
        }
    }
    
    echo "\n=== 检查签到日志表 ===\n";
    try {
        $stmt = $pdo->query("SELECT COUNT(*) as count FROM system_checkin_log");
        $result = $stmt->fetch();
        echo "签到记录数量: {$result['count']}\n";
    } catch (Exception $e) {
        echo "签到日志表检查失败: " . $e->getMessage() . "\n";
    }
    
} catch (Exception $e) {
    echo "数据库连接错误: " . $e->getMessage() . "\n";
}
